<script setup>
import { ref } from 'vue';

//添加更改密码数据模型
const passwordModel = ref({
    old_Pwd: '',
    new_Pwd: '',
    re_Pwd: ''
})

//密码校验规则
const rules = {
    old_Pwd: [
        { required: true, message: '请输入旧密码', trigger: 'blur' },
        {
            pattern: /^\S{5,16}$/,
            message: '昵称必须是5~16位的非空字符串',
            trigger: 'blur'
        }
    ],
    new_Pwd: [
        { required: true, message: '请输入新密码', trigger: 'blur' },
        {
            pattern: /^\S{5,16}$/,
            message: '昵称必须是5~16位的非空字符串',
            trigger: 'blur'
        }
    ],
    re_Pwd: [
        { required: true, message: '请再次输入新密码', trigger: 'blur' },
        {
            pattern: /^\S{5,16}$/,
            message: '昵称必须是5~16位的非空字符串',
            trigger: 'blur'
        }
    ]
}

//更新密码
import { userPasswordUpdateService } from '@/api/user.js'
import { ElMessage } from 'element-plus';

const updatePassword = async () => {
    //调用接口
    let result = await userPasswordUpdateService(passwordModel.value);
    ElMessage.success(result.msg ? result.msg : '修改成功');
}

</script>


<template>
    <el-card class="page-container">
        <template #header>
            <div class="header">
                <span>重置密码</span>
            </div>
        </template>
        <el-row>
            <el-col :span="12">
                <el-form :model="passwordModel" :rules="rules" label-width="100px" size="large">
                    <el-form-item label="旧密码" prop="old_Pwd">
                        <el-input v-model="passwordModel.old_Pwd"></el-input>
                    </el-form-item>
                    <el-form-item label="新密码" prop="new_Pwd">
                        <el-input v-model="passwordModel.new_Pwd"></el-input>
                    </el-form-item>
                    <el-form-item label="新密码" prop="re_Pwd">
                        <el-input v-model="passwordModel.re_Pwd"></el-input>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" @click="updatePassword">提交修改</el-button>
                    </el-form-item>
                </el-form>
            </el-col>
        </el-row>
    </el-card>
</template>